﻿using System;
using System.Windows;
using Rodunu.Clients.WPF.Controllers;

namespace Rodunu.Clients.WPF.Settings
{
    /// <summary>
    /// Interaction logic for Login.xaml
    /// </summary>
    public partial class Login
    {
        private LoginController _loginController;

        public event EventHandler LogUserOn;

        public string CurrentUserName
        {
            get { return (string)UserName.Content; }
            set
            {
                if (value.Length > 0)
                {
                    UserName.Content = value;
                    LoginButton.Visibility = System.Windows.Visibility.Collapsed;
                    UserName.Visibility = System.Windows.Visibility.Visible;
                }
            }
        }

        public Login()
        {
            InitializeComponent();

            LoginButton.Click += LoginButton_Click;
        }

        void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            if (LogUserOn != null)
                LogUserOn(sender, new EventArgs());
        }

        public void Run(LoginController loginController)
        {
            _loginController = loginController;

            if (_loginController.LoggedOnuser != null)
            {
                UserName.Content = _loginController.LoggedOnuser.UserName;
                LoginButton.Visibility = System.Windows.Visibility.Collapsed;
                UserName.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                LoginButton.Visibility = System.Windows.Visibility.Visible;
                UserName.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
    }
}
